package com.master.util.servlet;

import com.master.iu.*;
import com.master.util.*;
import com.master.util.ed.*;

public class EDI_ImportacaoThread
    extends Thread {

  long timeToSleep = (10 * 60 * 1000); //default 10 minutos.
  boolean activeThread = false;

  public EDI_ImportacaoThread (String str) {
    super (str);
  }

  public EDI_ImportacaoThread (String str , boolean activeThread) {
    super (str);
    if (activeThread) {
      activeThread ();
    }
  }

  public void activeThread () {
    // //  (">> START THREAD [" + Data.getHoraHM () + "]");
    synchronized (this) {
      activeThread = true;
      if (!isAlive ()) {
        start ();
      }
    }
  }

  public void stopThread () {
    // //  (">> STOP THREAD [" + Data.getHoraHM () + "]");
    synchronized (this) {
      activeThread = false;
      notify ();
    }
  }

  public long getTimeToSleepInMinuts () {
    return timeToSleep / 60000;
  }

  public void run () {

    while (true) {
      try {
        try {
          //*** Tempo de pausa da Thread
           sleep (timeToSleep);
        }
        catch (InterruptedException e) {}

        if (activeThread) {
          //new EDI_ImportacaoBean().importaArquivo ();
          // //  ("DONE! " + getName () + " [" + Data.getHoraHM () + "]");
        }
      }
      catch (Exception e) {
        e.printStackTrace ();
      }
    }
  }
}